package com.xauto.pioneer.appuser.activity.parking;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.xauto.pioneer.appuser.R;
import com.xauto.pioneer.appuser.activity.BaseActivity;
import com.xauto.pioneer.appuser.util.LicenseKeyboardUtil;
import com.xauto.pioneer.appuser.view.PromptDialog;

import butterknife.Bind;
import butterknife.OnClick;

/**输入车牌页面
 * Created by Administrator on 2018/5/23.
 */

public class InputCarNumberActivity extends BaseActivity {
    public static final String INPUT_LICENSE_COMPLETE = "com.towngood.carnum.input";
    public static final String INPUT_LICENSE_KEY = "LICENSE";

    @Bind(R.id.et_car_license_inputbox1)
    EditText inputbox1;
    @Bind(R.id.et_car_license_inputbox2)
    EditText inputbox2;
    @Bind(R.id.et_car_license_inputbox3)
    EditText inputbox3;
    @Bind(R.id.et_car_license_inputbox4)
    EditText inputbox4;
    @Bind(R.id.et_car_license_inputbox5)
    EditText inputbox5;
    @Bind(R.id.et_car_license_inputbox6)
    EditText inputbox6;
    @Bind(R.id.et_car_license_inputbox7)
    EditText inputbox7;
    @Bind(R.id.et_car_license_inputbox8)
    EditText inputbox8;
    @Bind(R.id.tv_divider7)
    TextView tv_divider7;

    /**切换车牌  0--普通车牌   1---新能源车牌*/
    public static int  INPUT_CARNUM = 0;
    @Bind(R.id.tv_switchcartype)
    TextView tv_switchcartype;


    private LicenseKeyboardUtil keyboardUtil;
    private PromptDialog promptDialog;
    @Override
    protected int getContentView() {
        return R.layout.ac_inputcarnum;
    }

    @Override
    protected void initView() {
        keyboardUtil = new LicenseKeyboardUtil(this,new EditText[]{inputbox1,inputbox2,inputbox3,
                inputbox4,inputbox5,inputbox6,inputbox7,inputbox8});
        keyboardUtil.showKeyboard();

        promptDialog = new PromptDialog(mContext, getString(R.string.notice), getString(R.string.text_not_network),
                getString(R.string.to_setting), getString(R.string.logout), getString(R.string.dialogpic_notice),new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //去设置
                promptDialog.dismiss();
            }
        }, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //退出
                promptDialog.dismiss();
            }
        });
    }
    IntentFilter finishFilter;
    BroadcastReceiver receiver;
    AlertDialog alertDialog;
    AlertDialog.Builder builder;
    @Override
    protected void initData() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        //输入车牌完成后的intent过滤器
        finishFilter = new IntentFilter(INPUT_LICENSE_COMPLETE);
        receiver =  new  BroadcastReceiver() {
            @Override
            public   void  onReceive(Context context, Intent intent) {
                String license = intent.getStringExtra(INPUT_LICENSE_KEY);
                Log.e("tag2",license);
                if(license != null && license.length() > 0){
                    builder = new AlertDialog.Builder(InputCarNumberActivity.this);
                    builder.setMessage("车牌号为:" + license);
                    alertDialog = builder.create();
                    alertDialog.setCancelable(true);
                    alertDialog.show();
                }

            }
        };
        this.registerReceiver(receiver, finishFilter);
    }



    @OnClick({R.id.tv_switchcartype})
    public void onClick(View v){
        switch (v.getId()){
           case  R.id.tv_switchcartype:
                if(INPUT_CARNUM==0){
                    INPUT_CARNUM=1;
                    tv_divider7.setVisibility(View.VISIBLE);
                    inputbox8.setVisibility(View.VISIBLE);
                    inputbox8.setText("");
                    tv_switchcartype.setText("切换普通车牌");
                }else if(INPUT_CARNUM ==1){
                    INPUT_CARNUM=0;
                    tv_divider7.setVisibility(View.GONE);
                    inputbox8.setVisibility(View.GONE);
                    tv_switchcartype.setText("切换新能源车牌");

                }
            break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        InputCarNumberActivity.this.unregisterReceiver(receiver);
    }
}
